package com.pay.manager.controller.system;




import com.pay.manager.dto.ChannelDTO;
import com.pay.manager.dto.MerchantSearchDTO;
import com.pay.manager.response.PageDataResult;
import com.pay.manager.service.ChannelService;
import com.pay.manager.service.MerchantService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;


/**
 * @Title: ChannelController
 * @Description: 渠道管理
 * @author: yjw
 * @version: 1.0
 * @date: 2020/06/12 15:17
 */
@Controller
@RequestMapping("channel")
public class ChannelController {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private ChannelService channelService;

	@RequestMapping("/channelManage")
	public String toPage() {
		logger.info("进入渠道信息管理");
		return "/channel/channelManage";
	}

	/**
	 *
	 * 功能描述: 分页查询用户列表
	 *
	 * @param:
	 * @return:
	 * @date: 2018/11/21 11:10
	 */
	@RequestMapping(value = "/getChannelList", method = RequestMethod.POST)
	@ResponseBody
	public PageDataResult getChannelList(@RequestParam("pageNum") Integer pageNum,
									   @RequestParam("pageSize") Integer pageSize, /* @Valid PageRequest page, */ ChannelDTO channelSearch) {
		/*
		 * logger.info("分页查询用户列表！搜索条件：userSearch：" + userSearch + ",pageNum:" +
		 * page.getPageNum() + ",每页记录数量pageSize:" + page.getPageSize());
		 */

		PageDataResult pdr = new PageDataResult();
		try {
			if (null == pageNum) {
				pageNum = 1;
			}
			if (null == pageSize) {
				pageSize = 10;
			}
			// 获取用户列表
			pdr = channelService.getChannelList(channelSearch, pageNum, pageSize);
			logger.info("渠道信息列表查询=pdr:" + pdr);

		} catch (Exception e) {
			e.printStackTrace();
			logger.error("渠道信息列表查询异常！", e);
		}
		return pdr;
	}


	 @RequestMapping(value = "/applyPass", method = RequestMethod.POST)
	 @ResponseBody 
	 public Map<String,Object> applyPass(Integer cid, String operationPwd) {
		 logger.info("渠道编号为"+cid+"的停止使用！");
		 Map<String,Object> data = new HashMap();
		 data = channelService.applyPass(cid,operationPwd);
		 return data;
	}
	 
	 @RequestMapping(value = "/lower", method = RequestMethod.POST)
	 @ResponseBody 
	 public Map<String,Object> lower(Integer cid,String operationPwd) {
		 logger.info("渠道编号为"+cid+"的停止使用！");
		 Map<String,Object> data = channelService.lower(cid,operationPwd);
		 return data;
	}

	@RequestMapping(value = "/addChannel", method = RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> addChannel(String channelId,String channelName,String channelMchId,String mchId,String param,String remark) {
		logger.info("渠道添加中！");
		Map<String,Object> data = channelService.addChannel(channelId,channelName,channelMchId,mchId,param,remark);
			return data;
	}
}
